const myRequest = (options) => {
	return new Promise((resolve, reject) => {
		var content_type
		if(options.header){
			if(options.header['content-type']){
				content_type=options.header['content-type']
			}
		}
		let header_tmp={
			'token':'',
			'content-type':content_type?content_type:'application/json;charset=UTF-8;multipart/form-data'
		}
		uni.showLoading({
			title: '加载中'
		});
		uni.request({
			url:  options.url,
			method: options.method || 'GET',
			data: options.data || {},
			header: header_tmp,
			success: (res) => {
				if (res.statusCode !== 200 && res.statusCode !== 201) {
					uni.hideLoading();
					return uni.showToast({
						icon: "error",
						title: "网络错误，请检查"
					})
				};
				uni.hideLoading();
				resolve(res)
			},
			fail: (err) => {
				uni.hideLoading();
				return uni.showToast({
					icon: "error",
					title: "请求接口失败"
				})
				reject(err)
			},


		})
	})

}

module.exports = myRequest;
